
cc.Class({
    extends: cc.Component,

    properties: {
        m_Bg:cc.Node,
        m_AirPlane:cc.Node,
    },
    ctor:function(){
        this.isCanTouch = false;
        this.isPlaying = false;
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.isCanTouch = false;
        this.isCanPlay = false;
        this.node.on(cc.Node.EventType.TOUCH_START, this.TouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE,this.TouchMove, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.TouchEnd, this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,this.TouchEnd, this);
    },

    //Methods

    TouchStart:function (event,target){
        this.m_Bg.runAction(cc.fadeOut(0.5));
        if(this.isPlaying ){ //isPlaying是true，就不能触发TouchStart函数，TouchStart要做，触摸，东西滑出屏幕外

            return;
        }
        this.isPlaying = true;
        // console.log('TouchStart',this.isCanTouch);
        //等待0.5s，刚开始不能触摸，要等待动画结束后，才能触摸，触摸会触发动作MoveOut
        this.scheduleOnce(function() {
            // 这里的 this 指向 component
            this.isCanTouch = true;
        }, 1);
        gameCtrl.setAction(ACTION_MOVE_OUT);


    },
    TouchMove:function(event,target){
        if( !this.isCanTouch ){ //不能触摸就不能触发TouchMove函数，触发TouchMove函数就代表可以玩了
            return;
        }
        this.m_AirPlane.getComponent('airPlane').startFire();
        let pos = event.getDelta();
        // console.log(pos);
        gameCtrl.movePlane(pos);
        // console.log('TouchMove');
        this.m_Bg.runAction(cc.fadeOut(0.5));


    },
    TouchEnd:function(){
        // console.log('TouchEnd');
        this.m_Bg.runAction(cc.fadeIn(0.5));
        this.m_AirPlane.getComponent('airPlane').endFire();

    },


});
